package licode.unisop.realm.application.service;

import cn.hutool.json.JSONUtil;
import licode.unisop.provider.api.SiUserProvider;
import licode.unisop.provider.info.*;
import licode.unisop.provider.vo.*;

import java.util.List;

/**
 * 实现Url远程用户插件
 *
 * @author licode
 */
public class SiUserProviderUrl extends SiUrlCallBase implements SiUserProvider {
    private static class SiUserPageResult extends SiPageResult<SiUser> {}

    public SiUserProviderUrl(SiRestfulCallUtil callUtil, String url) {
        super(callUtil, url);
    }

    @Override
    public String findUserId(SiAccount account) {
        return execute("lookupUserId", JSONUtil.toJsonStr(account));
    }

    @Override
    public SiUser findUserByAccount(SiAccount account) {
        return JSONUtil.toBean(execute("findUserByAccount", JSONUtil.toJsonStr(account)), SiUser.class);
    }

    @Override
    public List<SiUser> queryUsers(SiQueryUserIn userIn) {
        return JSONUtil.toBean(execute("queryUsers", JSONUtil.toJsonStr(userIn)), List.class);
    }

    @Override
    public SiUser findUserById(UserIdInfo idFind) {
        return JSONUtil.toBean(execute("findUserById", JSONUtil.toJsonStr(idFind)), SiUser.class);
    }

    @Override
    public SiUserGroup lookupUserGroup(UserGroupLookupIn req) {
        return null;
    }

    @Override
    public void addUser(SiUser user) {
        execute("addUser", JSONUtil.toJsonStr(user));
    }

    @Override
    public void updateUser(SiUser user) {
        execute("updateUser", JSONUtil.toJsonStr(user));
    }

    @Override
    public void batchAddUser(UserBatchInfo batchInfo) {
        execute("batchAddUser", JSONUtil.toJsonStr(batchInfo));
    }

    @Override
    public SiAccountSet findAccount(UserIdInfo idFind) {
        return JSONUtil.toBean(execute("findAccount", JSONUtil.toJsonStr(idFind)), SiAccountSet.class);
    }

    @Override
    public void saveAccountSet(SiAccountSet info) {
        execute("saveAccountSet", JSONUtil.toJsonStr(info));
    }

    @Override
    public void saveAccount(SiAccountIn info) {

    }

    @Override
    public String getName() {
        return "";
    }

    @Override
    public long getUserCount(SiRealmId realmId) {
        return Long.parseLong(execute("getUserCount", JSONUtil.toJsonStr(realmId)));
    }

    @Override
    public SiPageResult<SiUser> findPage(UserPageInfo req) {
        return JSONUtil.toBean(execute("findUserPage", JSONUtil.toJsonStr(req)), SiUserPageResult.class);
    }

    @Override
    public SiIdentitySet findIdentity(UserIdInfo idFind) {
        return JSONUtil.toBean(execute("findIdentity", JSONUtil.toJsonStr(idFind)), SiIdentitySet.class);
    }

    @Override
    public void saveIdentitySet(SiIdentitySet info) {
        execute("saveIdentitySet", JSONUtil.toJsonStr(info));
    }

    @Override
    public void saveIdentity(SiIdentityIn info) {

    }

    @Override
    public void updateLoginTime(SiUserLoginTimeIn loginTimeIn) {
        execute("updateLoginTime", JSONUtil.toJsonStr(loginTimeIn));
    }

    @Override
    public void saveUserGroup(UserGroupSaveIn group) {

    }

    @Override
    public void assignGroupToUsers(SiGroupAssignToUsersIn req) {

    }

    @Override
    public List<SiUserGroup> findAssignGroup(UserGroupQueryIn req) {
        return null;
    }

    @Override
    public SiPageResult<SiUserGroup> findUserGroupPage(UserGroupQueryPageIn req) {
        return null;
    }

    @Override
    public SiPageResult<SiRealmPlatform> findRealPlatform(SiRealmAssignPlatPageIn req) {
        return null;
    }

    @Override
    public List<SiRealmPlatform> findRealPlatformOther(SiRealmPlatformOtherIn req) {
        return null;
    }

    @Override
    public String getRealmAssignToPlatform(String platformId) {
        return null;
    }

    @Override
    public void clearGroupsOfPlatform(SiRealmGroupsOfPlatClearIn req) {

    }

    @Override
    public void saveGroupsOfPlatform(SiUserGroupsAssignToPlatIn req) {

    }

    @Override
    public void assignGroupsToPlatform(SiUserGroupsAssignToPlatIn req) {

    }

    @Override
    public void assignPlatsToUserGroup(SiPlatsAssignToUserGroupIn req) {

    }

    @Override
    public long removeGroupFromPlatform(UserGroupRemoveFromPlatIn req) {
        return 0;
    }

    @Override
    public void removeUsersFromGroup(UsersRemoveFromGroupIn req) {

    }
}
